#ifndef INPUTENGINE_HPP_
#define INPUTENGINE_HPP_

#include <SFML/Graphics.hpp>

namespace OForce_Input {

struct KeyState {
  sf::Keyboard::Key up;
  sf::Keyboard::Key down;
  sf::Keyboard::Key left;
  sf::Keyboard::Key right;
  sf::Keyboard::Key menu;
  sf::Keyboard::Key cancel;
  sf::Keyboard::Key action;
}; // struct KeyState

struct JoyState {
  unsigned int up;
  unsigned int down;
  unsigned int left;
  unsigned int right;
  unsigned int menu;
  unsigned int cancel;
  unsigned int action;
}; // struct JoyState

class InputEngine {
public: 
  ~InputEngine() {}
  static InputEngine* Instance();
  // EventHandler should only be called during the main game loop
  void EventHandler(sf::Event Event);
  void RestoreDefaultKeys();
  void RestoreDefaultJoyButtons();
  void saveInputSettings();	
  // Input state functions.
  // Use these to check to see if any buttons are pressed
  bool UpState() {return upState;}
  bool DownState() {return downState;}
  bool LeftState() {return leftState;}
  bool RightState() {return rightState;}
  bool MenuState() {return menuState;}
  bool CancelState() {return cancelState;}
  bool ActionState() {return actionState;}
  // Checks for press state
  bool UpPress() {return upPress;}
  bool DownPress() {return downPress;}
  bool LeftPress() {return leftPress;}
  bool RightPress() {return rightPress;}
  bool MenuPress() {return menuPress;}
  bool CancelPress() {return cancelPress;}
  bool ActionPress() {return actionPress;}
  bool QuitPress() {return quitPress;}
  // Checks for release state
  bool UpReleased() {return upReleased;}
  bool DownReleased() {return downReleased;}
  bool LeftReleased() {return leftReleased;}
  bool RightReleased() {return rightReleased;}
  bool MenuReleased() {return menuReleased;}
  bool CancelReleased() {return cancelReleased;}
  bool ActionReleased() {return actionReleased;}
private: 
  // Functions
  InputEngine();
  static InputEngine *m_pInstance;
  void keyHandler(sf::Event event);
  void joyHandler(sf::Event event);
  void setNewKey(sf::Keyboard::Key &oldKey, sf::Keyboard::Key newKey);
  void setNewJoyButton(int &oldJoy, int newJoy);
  // Variables
  KeyState mKey;
  JoyState mJoy;
  // Where's the any key?
  bool anyKeyPressed;
  bool anyKeyReleased;
  // Input states: whether buttons are currently pressed
  bool upState;
  bool downState;
  bool leftState;
  bool rightState;
  bool menuState;
  bool cancelState;
  bool actionState;
  // Input pressed bools
  bool upPress;
  bool downPress;
  bool leftPress;
  bool rightPress;
  bool menuPress;
  bool cancelPress;
  bool actionPress;
  bool quitPress;
  // Input released bools
  bool upReleased;
  bool downReleased;
  bool leftReleased;
  bool rightReleased;
  bool menuReleased;
  bool cancelReleased;
  bool actionReleased;
  // SFML event 
  sf::Event mEvent;
}; // class InputEngine

} // namespace OForce_Input

#endif 
